package com.cn.lf.wx.dacs.bussiness.author.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cn.lf.wx.dacs.bussiness.author.common.Constant;
import com.cn.lf.wx.dacs.bussiness.author.dao.EsdrMapper;
import com.cn.lf.wx.dacs.bussiness.author.serviceImpl.EsdrService;

@RestController("apiController")
@RequestMapping("/api")
public class ApiController extends Base {
	
	@Autowired
	private EsdrService esdrService;
	
	
	@RequestMapping("/esdrRetrieval")
	public String esdrRetrieval(String sfz,String time) {
		Map<String,Object> endMap = new HashMap<String, Object>();
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("time", time + "%");
		map.put("sfz", sfz);
		for(int i = 0;i<Constant.esdrbytime.length;i++) {
			String tablename ="V_ESDR_" +  Constant.esdrbytime[i];
			map.put("tablename", tablename);
			List<Map<String,Object>> lists =  esdrService.getListbytime(map);
//			for(int z =0;z<lists.size();z++) {
//				lists.get(z).remove("SFZH");
//				if(tablename.equals("V_ESDR_INP_PATIENT")) {
//					lists.get(z).remove("ID_NO");
//				}
//			}
			endMap.put(tablename, lists);
			map.remove("tablename");
		}
		List<Map<String,Object>> ddlists =  esdrService.getListbysfz(sfz);
		endMap.put("V_ESDR_OUTP_PATIENT", ddlists);
		JSONObject json = new  JSONObject(endMap);
		return json.toString();
	}
	
	@RequestMapping("/esdrDictionary")
	public String esdrDictionary() {
		Map<String,Object> endMap = new HashMap<String, Object>();
		Map<String,Object> map = new HashMap<String, Object>();
		for(int i = 0;i<Constant.esdrnotime.length;i++) {
			String tablename = "V_ESDR_"  + Constant.esdrnotime[i];
			map.put("tablename", tablename);
			List<Map<String,Object>> lists =  esdrService.getListnotime(map);
			endMap.put(tablename, lists);
			map.remove("tablename");
		}
		JSONObject json = new  JSONObject(endMap);
		return json.toString();
	}
	@RequestMapping("/gettest")
	public String gettest(String sfz,String time) {
		Map<String,Object> endMap = new HashMap<String, Object>();
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("time", time + "%");
		map.put("sfz", sfz);
		List<Map<String,Object>> lists =  esdrService.gettest(map);
		endMap.put("test", lists);
		JSONObject json = new  JSONObject(endMap);
		return json.toString();
	}
	
}
